﻿<%@ Page Title="Edit Courses" Language="C#" MasterPageFile="/Administration/Site.Master" AutoEventWireup="true" CodeBehind="EditCourses.aspx.cs" Inherits="AdministrationWeb.Administration.EditCourses" %>

<asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" runat="server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="headerText" runat="server">
    Edit Courses
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="MainContent" runat="server">
    &nbsp;<br />
    Search:
    <asp:TextBox ID="txtCourseSearch" runat="server" Width="300px"></asp:TextBox>
    &nbsp;&nbsp;&nbsp;
    <asp:Button ID="btnSearch" runat="server" OnClick="btnSearch_Click" Text="Search" CssClass="button" />
    &nbsp;&nbsp;
    <br />
    <br />
    <br />
    <asp:SqlDataSource ID="SqlCourses" runat="server" ConnectionString="<%$ ConnectionStrings:ApplicationConnectionString %>" ProviderName="<%$ ConnectionStrings:ApplicationConnectionString.ProviderName %>"
        OldValuesParameterFormatString="original_{0}" SelectCommand="SELECT course_id, course_name,
	(SELECT count(*) FROM mentor m
	WHERE m.benneficial_course1 = c.course_id
	OR  m.benneficial_course2 = c.course_id
	OR	m.benneficial_course3 = c.course_id) AS num_mentors
FROM lkup_courses c
WHERE LCASE(c.course_name) LIKE LCASE(CONCAT('%', ?SearchName, '%'))
ORDER BY course_name" ConflictDetection="CompareAllValues" DeleteCommand="DELETE FROM lkup_courses
WHERE course_id = ?original_course_id
AND course_name = ?original_course_name" InsertCommand="INSERT INTO lkup_courses (course_name)
VALUES(?course_name)" UpdateCommand="UPDATE lkup_courses
SET course_name = ?course_name
WHERE course_id = ?original_course_id
AND course_name = ?original_course_name">
        <DeleteParameters>
            <asp:Parameter Name="original_course_id" />
            <asp:Parameter Name="original_course_name" />
        </DeleteParameters>
        <InsertParameters>
            <asp:ControlParameter ControlID="txtNewName" Name="course_name" PropertyName="Text" />
        </InsertParameters>
        <SelectParameters>
            <asp:ControlParameter ControlID="txtCourseSearch" DefaultValue="%" Name="SearchName" PropertyName="Text" />
        </SelectParameters>
        <UpdateParameters>
            <asp:Parameter Name="course_name" />
            <asp:Parameter Name="original_course_id" />
            <asp:Parameter Name="original_course_name" />
        </UpdateParameters>
    </asp:SqlDataSource>
    <asp:GridView ID="gdvCourses" runat="server" DataSourceID="SqlCourses" AllowPaging="True" AllowSorting="True" AutoGenerateColumns="False" BorderColor="#006600"
        BorderStyle="Double" CellPadding="4" ForeColor="#333333" OnRowUpdated="gdvCourses_RowUpdated" OnRowDeleted="gdvCourses_RowDeleted" 
        DataKeyNames="course_id">
        <AlternatingRowStyle BackColor="White" />
        <Columns>
            <asp:BoundField DataField="course_id" HeaderText="Id" ReadOnly="True" DataFormatString="{0:d}" Visible="False">
                <ItemStyle HorizontalAlign="Center" Width="100px" />
            </asp:BoundField>
            <asp:TemplateField AccessibleHeaderText="Name" HeaderText="Name">
                <EditItemTemplate>
                    <asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("course_name") %>' Width="500px"></asp:TextBox>
                    <br />
                    <asp:RequiredFieldValidator ID="rfvUpdate" runat="server" ControlToValidate="TextBox1" ErrorMessage="*Name can not be empty" ForeColor="Red" ValidationGroup="1"></asp:RequiredFieldValidator>
                </EditItemTemplate>
                <ItemTemplate>
                    <asp:Label ID="Label1" runat="server" Text='<%# Bind("course_name") %>'></asp:Label>
                </ItemTemplate>
                <ItemStyle Width="735px" />
            </asp:TemplateField>
            <asp:BoundField DataField="num_mentors" HeaderText="Mentors" ReadOnly="True">
                <ItemStyle HorizontalAlign="Center" VerticalAlign="Middle" Width="120px" />
            </asp:BoundField>
            <asp:CommandField ButtonType="Button" ShowEditButton="True" ValidationGroup="1" >
            <ControlStyle CssClass="button" Width="90" />
            <ItemStyle HorizontalAlign="Center" Width="96" />
            </asp:CommandField>
            <asp:ButtonField ButtonType="Button" CommandName="Delete" Text="Delete">
            <ControlStyle CssClass="button" Width="90" />
            <ItemStyle HorizontalAlign="Center" Width="96" />
            </asp:ButtonField>
        </Columns>
        <EditRowStyle BackColor="#7C6F57" />
        <FooterStyle BackColor="#1C5E55" Font-Bold="True" ForeColor="White" />
        <HeaderStyle BackColor="#1C5E55" Font-Bold="True" ForeColor="White" />
        <PagerStyle BackColor="#666666" ForeColor="White" HorizontalAlign="Center" />
        <RowStyle BackColor="#E3EAEB" />
        <SelectedRowStyle BackColor="#C5BBAF" Font-Bold="True" ForeColor="#333333" />
        <SortedAscendingCellStyle BackColor="#F8FAFA" />
        <SortedAscendingHeaderStyle BackColor="#246B61" />
        <SortedDescendingCellStyle BackColor="#D4DFE1" />
        <SortedDescendingHeaderStyle BackColor="#15524A" />
    </asp:GridView>
    &nbsp;*Note-If you delete a course it wil also delete that course for all attached mentors.<br />
    <br />
    <br />
    <hr />
    <br />
    <strong>Create New Course</strong><br />
    <br />
    Course Name:&nbsp;
    <asp:TextBox ID="txtNewName" runat="server" Width="300px" ValidationGroup="2"></asp:TextBox>
    &nbsp;&nbsp;&nbsp;
    <asp:RequiredFieldValidator ID="rfvCourse" runat="server" ErrorMessage="*Must enter a Course name" ForeColor="Red" ControlToValidate="txtNewNAme" ValidationGroup="2">*Must enter a course name</asp:RequiredFieldValidator>
    <br />
    <br />
    <asp:Button ID="btnInsert" runat="server" Text="Create New course" OnClick="btnInsert_Click" ValidationGroup="2" CssClass="button" />
    <br />
    <br />
    <asp:Label ID="lblMessage" runat="server" Font-Italic="True" Font-Size="Smaller" ViewStateMode="Enabled"></asp:Label>
    <br />
</asp:Content>
